home *** CD-ROM | disk | FTP | other *** search
/ Exploring Where & Why / Exploring Where & Why.iso / pc / MODULES / LESSON01 / ACT01A / common1.cst / 00056_DragAndChange.ls < prev    next >
Encoding:
Text File  |  2003-05-01  |  4.1 KB  |  111 lines

  1. --Drags sprite 1 over sprite 2 and changes sprite 2 on mouseUp event. Sprite 1 returns to original location or hides. 
  2. --Ex: coloring a sprite with pencils.  The sprite can be changed many times.
  3.  
  4. property pbasketSprite,pmaskSprite,phideDraggables
  5.  
  6. on new me, tSprite,mSprite,hDrag
  7.   set pbasketSprite=tSprite  --a basket for draggables.
  8.   set pmaskSprite=mSprite    --a hilite sprite displayed on rollover of basket sprite
  9.   set phideDraggables=hDrag  --checks if draggables have to be hidden or put back
  10.   return me
  11. end
  12.  
  13.  
  14. on initDragAndChange me,finalCast
  15.   if field "new names"<>"" then
  16.     set nLines=the linecount of member "new names"
  17.     repeat with i=1 to nLines
  18.       set newName=item 1 of line i of field "new names"
  19.       set oldName=item 2 of line i of field "new names"
  20.       if newName contains "glasses" then
  21.         set newName=the name of member 4 of castLib finalCast
  22.         set oldName="glasses"
  23.       end if
  24.       set the name of member newName of castLib finalCast=oldName
  25.     end repeat
  26.     put "" into field "new names"
  27.   end if
  28. end
  29.  
  30.  
  31. --changes cursor to "hand" on rollover
  32. on psMouseEnter me,spr
  33.   set cursor = the number of member "hand"
  34.   set mask = the number of member "hand mask"
  35.   set the cursor of sprite spr=[cursor,mask]
  36. end
  37.  
  38.  
  39. on psMouseDown me,spr,maskSpr
  40.   puppetSprite spr,true
  41.   if not voidP(maskSpr) then set pmaskSprite=maskSpr
  42. end
  43.  
  44.  
  45. --makes the sprite movable and checks if it intersects with "basket" sprite. On rollover:
  46. --1) if 'pmaskSprite' is 'pbasketSprite', then basket sprite itself hilites (as a mask)
  47. --2) if 'pmaskSprite' is not 'pbasketSprite', then another hidden sprite is displayed as a mask. 
  48. --   In this case a basket sprite is an invisible shape, and used then basket has
  49. --   to be invisible and be visible as a mask (another hidden sprite) when rolled over.
  50. on psMouseWithin me,spr
  51.   set the moveableSprite of sprite spr=true
  52.   if sprite spr intersects pbasketSprite then
  53.     set the ink of sprite pmaskSprite=4  --not copy
  54.     set basketLoc=the loc of sprite pbasketSprite
  55.     set the loc of sprite pmaskSprite=basketLoc
  56.     if the regPoint of the member of sprite pmaskSprite=basketLoc then
  57.       set the loc of sprite pmaskSprite=(basketLoc)*2
  58.     end if
  59.   else
  60.     if pmaskSprite<>pbasketSprite then set the loc of sprite pmaskSprite=point(1000,1000)
  61.     set the ink of sprite pmaskSprite=8  --matte
  62.   end if
  63.   updateStage
  64. end
  65.  
  66.  
  67.  
  68. --replaces the member of basket sprite with a corresponding member from "draggablesswitch" cast
  69. on psMouseUp me,spr,finalCast,partName,ink
  70.   set switchflag=0
  71.   set theInk=8
  72.   if not voidP(ink) then set theInk=ink
  73.   set the ink of sprite pbasketSprite=theInk  --matte
  74.   if sprite spr intersects pbasketSprite then
  75.     set dragName=the name of the member of sprite spr
  76.     set maskName=the name of the member of sprite pmaskSprite
  77.     if pmaskSprite<>pbasketsprite then set the loc of sprite pmaskSprite=point(1000,1000)
  78.     --JCODE
  79.     set theMemName = maskName&"."&dragName
  80.     set switchMember=member theMemName of castLib "draggablesswitch"
  81.     --END JCODE
  82.     set the member of sprite pbasketSprite=switchMember
  83.     set the rect of sprite pbasketSprite=the rect of sprite pmaskSprite
  84.     updatestage
  85.     
  86.     --records selected image by putting it into 'finalCast' 
  87.     if not voidP(partName) then
  88.       set the picture of member partName of castLib finalCast=the picture of the member of sprite pbasketSprite
  89.       set the name of member partName of castLib finalCast=dragName 
  90.       put dragName&","&partName into line (the linecount of member "new names" + 1) of field "new names"
  91.     else
  92.       set the picture of member maskName of castLib finalCast=the picture of switchMember
  93.     end if
  94.     
  95.     --records a member location on the stage as its reg. point. 
  96.     set the regPoint of member maskName of castLib finalCast=the loc of sprite pbasketSprite 
  97.     --hides draggables if needed
  98.     if phideDraggables then set the loc of sprite spr=point(1000,1000) 
  99.     set switchflag=1
  100.   end if
  101.   set the moveableSprite of sprite spr=false
  102.   if not phideDraggables or switchFlag=0 then puppetSprite spr,false
  103.   updateStage
  104.   return switchflag
  105. end
  106.  
  107.  
  108.  
  109.  
  110.  
  111.